#!/bin/bash

do_gnuplot_apache()
{
	app=apache
	title=cmp_qps_${app}
	title1=static
	data1=results/reply_time_${app}_${title1}.csv
	title2=app
	data2=results/reply_time_${app}_${title2}.csv
	title3=app_data
	data3=results/reply_time_${app}_${title3}.csv
	output_file=plots/${title}.png
	if [ -e $data ] ; then
		echo "plotting $title"
		gnuplot <<EOF
# set output
set terminal png
set output "$output_file"
# graph title
set title "$title"
# nicer aspect ratio for image size
set size 1,0.7
# y-axis grid
set grid y
# x-axis label
set xlabel "load"
# y-axis label
set ylabel "qps"
plot "$data1" using 1:(1000/\$2) smooth sbezier with lines title "$title1", "$data2" using 1:(1000/\$2) smooth sbezier with lines title "$title2", "$data3" using 1:(1000/\$2) smooth sbezier with lines title "$title3"
EOF
	fi
}

do_gnuplot_django()
{
	app=django
	title=cmp_qps_${app}
	title1=app
	data1=results/reply_time_${app}_${title1}.csv
	title2=app_data
	data2=results/reply_time_${app}_${title2}.csv
	output_file=plots/${title}.png
	if [ -e $data ] ; then
		echo "plotting $title"
		gnuplot <<EOF
# set output
set terminal png
set output "$output_file"
# graph title
set title "$title"
# nicer aspect ratio for image size
set size 1,0.7
# y-axis grid
set grid y
# x-axis label
set xlabel "load"
# y-axis label
set ylabel "qps"
plot "$data1" using 1:(1000/\$2) smooth sbezier with lines title "$title1", "$data2" using 1:(1000/\$2) smooth sbezier with lines title "$title2"
EOF
	fi
}


do_gnuplot_apache_django()
{
	app1=apache
	app2=django
	title=cmp_qps_${app1}_${app2}
	title1="$app1 - app"
	data1=results/reply_time_${app1}_app.csv
	title2="$app2 - app"
	data2=results/reply_time_${app2}_app.csv
	title3="$app1 - app_data"
	data3=results/reply_time_${app1}_app_data.csv
	title4="$app2 - app_data"
	data4=results/reply_time_${app2}_app_data.csv
	output_file=plots/${title}.png
	if [ -e $data ] ; then
		echo "plotting $title"
		gnuplot <<EOF
# set output
set terminal png
set output "$output_file"
# graph title
set title "$title"
# nicer aspect ratio for image size
set size 1,0.7
# y-axis grid
set grid y
# x-axis label
set xlabel "load"
# y-axis label
set ylabel "qps"
plot "$data1" using 1:(1000/\$2) smooth sbezier with lines title "$title1", "$data2" using 1:(1000/\$2) smooth sbezier with lines title "$title2", "$data3" using 1:(1000/\$2) smooth sbezier with lines title "$title3", "$data4" using 1:(1000/\$2) smooth sbezier with lines title "$title4"
EOF
	fi
}

do_gnuplot_apache
do_gnuplot_django
do_gnuplot_apache_django

